<?
class xml
{
	var $type;

	function xml ($phptype)
    {
		$this->type = $phptype;
		if ($this->type == "PHP4")
        {
           //
        }else
        {

        }
	}

	function loadFromFile ($filename)
    {
		if ($this->type == "PHP4")
        {
          $doc = domxml_open_file($filename);
		  return $doc;
		} else  //PHP5
        {
          $doc = new DOMDocument();
          @$doc->load($filename);
          return $doc;
		}
	}
	
	function loadFromString($str)
	{	    
		if ($this->type == "PHP4")
        {
          $doc = domxml_open_mem($str);
		  return $doc;
		} else  //PHP5
        {
          $doc = new DOMDocument();
          @$doc->loadXML($str); 
          return $doc;
		}	    
	}
	

	function getRoot ($xml)
    {
		if ($this->type == "PHP4")
        {
    			return $xml->document_element();
    	} else  //PHP5
        {
    			return $xml;
    	}
	}

	function getElements ($doc_,$name)
    {
	    if ($this->type == "PHP4")
        {
              return $doc_->get_elements_by_tagname($name);
		}else //PHP5
        {
              return $doc_->getElementsByTagName($name);
		}
	}

	//return value of node or empty string
	function getElementValueByName($doc_,$name)
    {
        foreach ($this->getElements($doc_,$name) as $elem)
        {
           return $this->getValue($elem);    
        }
        return "";        
	}
	
	function getValue ($node)
    {
		if ($this->type == "PHP4")
        {
          $childs = $node->child_nodes();
          if(count($childs)>0)
          {
             return $childs[0]->node_value();
          }else
          {
             return $node->node_value();
          }
		} else //PHP5
        {
			return $node->nodeValue;
		}
	}

	function toString($doc,$node)
	{ 
		if ($this->type == "PHP4")
        {
            return $node->dump_node();
		} else //PHP5
        {
			return $doc->saveXML($node);
		}
	}
		
	function getAttribute ($node,$name)
    {
		if ($this->type == "PHP4")
        {
		    return $node->get_attribute($name);
		}else //PHP5
        {
			return $node->getAttribute($name);
		}
	}

	function getXMLAsString($doc)
	{
		if ($this->type == "PHP4")
        {
            return $doc->dump_mem(true);
		} else //PHP5
        {
			return $doc->saveXML();
		}
    }
}
?>